#ifndef NETWORKMONITOR_H
#define NETWORKMONITOR_H

#include <QObject>
#include <QTimer>
#include <QRandomGenerator>
#include <QVariant>
#include <QVariantList>
#include <QVariantMap>

class NetworkMonitor : public QObject
{
    Q_OBJECT
    Q_PROPERTY(int totalStations READ totalStations NOTIFY totalStationsChanged)
    Q_PROPERTY(int onlineUsers READ onlineUsers NOTIFY onlineUsersChanged)
    Q_PROPERTY(double avgSignalQuality READ avgSignalQuality NOTIFY avgSignalQualityChanged)
    Q_PROPERTY(int abnormalStations READ abnormalStations NOTIFY abnormalStationsChanged)
    Q_PROPERTY(QString overallStatus READ overallStatus NOTIFY overallStatusChanged)

public:
    explicit NetworkMonitor(QObject *parent = nullptr);

    int totalStations() const { return m_totalStations; }
    int onlineUsers() const { return m_onlineUsers; }
    double avgSignalQuality() const { return m_avgSignalQuality; }
    int abnormalStations() const { return m_abnormalStations; }
    QString overallStatus() const { return m_overallStatus; }

    Q_INVOKABLE void startMonitoring();
    Q_INVOKABLE void stopMonitoring();
    Q_INVOKABLE QVariantList getSignalTrendData();
    Q_INVOKABLE bool saveReportFile(const QString &fileName, const QString &content);
    
    // 设置统计数据（从 BaseStationModel 传入）
    void setStatistics(int abnormalCount, double avgSignal);
    void setTotalStations(int total);

signals:
    void totalStationsChanged();
    void onlineUsersChanged();
    void avgSignalQualityChanged();
    void abnormalStationsChanged();
    void overallStatusChanged();
    void alarmTriggered(const QString &stationId, const QString &message, const QString &severity);

private slots:
    void updateData();

private:
    void updateStatus();

    QTimer *m_timer;
    int m_totalStations;
    int m_onlineUsers;
    double m_avgSignalQuality;
    int m_abnormalStations;
    QString m_overallStatus;
    QList<double> m_signalHistory;
};

#endif // NETWORKMONITOR_H

